<%@ page import="java.util.ArrayList" %><%--
  Created by IntelliJ IDEA.
  User: 白菜你个cabbage
  Date: 2019/11/7
  Time: 11:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>历史类图书</title>
</head>
<body>
<div align="center">
    <h2 align="center">欢迎来到21世纪书店</h2>
    图书分类>>>
    <a href="historyBook.jsp">历史类图书</a>
    <a href="IT.jsp">计算机类图书</a><br>

    <p>***书籍列表***</p>
    <form action="" method="post">
        <input type="text" name="book" value="《鱼羊野史》高晓松 178.1元" size="40" maxlength="200" readonly>
        <input type="submit" name="add" value="加入购物车" height="2">
    </form>

    <form action="" method="post">
        <input type="text" name="book" value="《明朝那些事儿》当年明月 199.0元" size="40" maxlength="200" readonly>
        <input type="submit" name="add" value="加入购物车" height="2">
    </form>

    <%
        request.setCharacterEncoding("utf-8");
        //获取要加入购物车的图书名
        String book = request.getParameter("book");
        //获取session
        ArrayList books = (ArrayList) session.getAttribute("books");
        if (books == null) {
            books = new ArrayList();
            session.setAttribute("books", books);
        }
        if (book != null) {
            books.add(book);
            out.println("<script type='text/javascript'>alert('加入购物车成功');</script>");
        }
    %>
    <br>
    <input type="button" value="查看我的购物车 " onClick="location.href='CarT.jsp'"><br>
</div>
</body>
</html>
